<script type="text/javascript">
    $('#myTab a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    })
</script>
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <p class="size">{%=o.formatFileSize(file.size)%}</p>
            {% if (!o.files.error) { %}
                <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
            {% } %}
        </td>
        <td>
            {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start">
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>Start</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>Cancel</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>

<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
            <span class="preview">
                {% if (file.thumbnailUrl) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name">
                {% if (file.url) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
            </p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
        </td>
        <td>
            {% if (file.deleteUrl) { %}
                <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                    <i class="glyphicon glyphicon-trash"></i>
                    <span>Delete</span>
                </button>
                <input type="checkbox" name="delete" value="1" class="toggle">
            {% } else { %}
                <button class="btn btn-warning cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>Cancel</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>
                <?php
                $judul = '';
                $link = '';
                $jenis = array('1' => 'rumah', '2' => 'apartemen', '3' => 'tanah', '4' => 'ruko dan kios',
                    '5' => 'ruang kantor', '6' => 'indekost', '7' => 'hotel dan villa', '8' => 'gudang', '9' => 'lainnya');
                $beli = array('1' => 'dijual', '2' => 'disewa', '3' => 'dicari');

                $sertifikasi = array('1' => 'SHM-Sertifikat', '2' => 'Hak Milik', '3' => 'HGB', '4' => 'lainnya(PPJB,adat,dll)');
                $furnitur = array('1' => 'Fully furnished', '2' => 'Semi furnished', '3' => 'Unfurnished');
                $fasilitas = array('1' => 'kolam renang', '2' => 'gym', '3' => 'sauna', '4' => 'tennis court',
                    '5' => 'jogging track', '6' => 'function room', '7' => 'children play ground', '8' => 'ATM', '9' => 'mini market',
                    '10' => 'library', '11' => 'shopping center', '12' => 'entertainment center');

                $provinsi = array('jakarta' => 'DKI Jakarta', 'jateng' => 'Jawa Tengah', 'jabar' => 'Jawa Barat');

                if ($isUpdate == TRUE) {
                    $judul = 'Ubah Properti';
                    $link = site_url('admin/listing/update_listing/' . $properti_id);
                    $submit = 'Update';
                } else {
                    $judul = 'Tambah Properti';
                    $link = site_url('admin/listing/tambah_listing');
                    $submit = 'Tambah';
                }

                $sewaBeli = "";
                $sewaBeli = $sewa_beli;
                /*function generate_option($array=array(), $sel='') {
                    $x = '';
                    foreach ($array as $key => $val) {
                        if ($key == $sel) {
                            $selected = set_select('option', $sel, TRUE);
                        } else {
                            $selected = set_select('option', $sel);
                        }
                        echo '<option value="' . $key . '" ' . $selected . '>' . $val . '</option>';
                    }
                    return $array[$x];
                }

                function generate_input($type='', $array=array(), $name='', $sel='') {
                    if ($type == 'radio') {
                        foreach ($array as $key => $val) {
                            echo '<input type="' . $type . '" name="' . $name . '" value="' . $key . '"/>' . $val . '&nbsp;';
                        }
                    } else {
                        foreach ($array as $key => $val) {
                            echo '<input type="' . $type . '" name="' . $key . '" value="' . $key . '"/>' . $val . '&nbsp;';
                        }
                    }
                }*/
                function generate_option($array=array(), $sel='') {
                    $x = '';
                    foreach ($array as $key => $val) {
                        if($sel == $key){
                            echo '<option value="' . $key . '" selected="">' . $val . '</option>';
                        } else {
                            echo '<option value="' . $key . '">' . $val . '</option>';
                        }
                    }
                    return $array[$x];
                }

                function generate_input($span='', $type='', $array=array(), $name='', $a=array(), $isUpdate="") {
                    $checked = "";
                    if ($type == 'radio') {
                        foreach ($array as $key => $val) {
                            if($a == $key){ 
                                echo '<div class="' . $span . '"><label class="radio checked"><input data-toggle="radio" type="' . $type . '" name="' . $name . '" value="' . $key . '">' . $val . '&nbsp;</label></div>';                            
                            } else {
                                echo '<div class="' . $span . '"><label class="radio unchecked"><input data-toggle="radio" type="' . $type . '" name="' . $name . '" value="' . $key . '">' . $val . '&nbsp;</label></div>';
                            }
                        }
                    } else {
                        foreach ($array as $key => $val) {
                            echo '<input type="' . $type . '" name="' . $key . '" value="' . $key . '"/>' . $val . '&nbsp;';
                        }
                    }
                }
                ?>
<div class="page dashboard">
    <div class="container">
        <div class="row">
            <ul class="span3 nav nav-list menu-sidebar">
                <div style="margin-bottom:10px;" >Selamat Datang, <?php echo anchor(site_url('admin/dashboard'), $this->session->userdata('username')); ?></div>
                <li class=""><?php echo anchor(site_url('admin/profil/form_update_user/'.$this->session->userdata('user_id')),'Edit Profil');?></li>
                <li class="aktif"><?php echo anchor(site_url('admin/listing'),'Kelola Listing');?></li>
                <?php if($level_user == 1){ ?>
                <li class=""><?php echo anchor(site_url('admin/profil'),'Kelola Agen');?></li>
                <li class=""><?php echo anchor(site_url('admin/artikel'),'Kelola Artikel');?></li>
                <li class=""><?php echo anchor('http://localhost/artyproperty/editor/properti_baru.php','Kelola Properti Baru');?></li>
                <?php } ?>
            </ul>
            <div class="span9 detail-profil">
                <ul class="nav nav-tabs" id="myTab">
                    <li class="active"><a href="#informasi_dasar" data-toggle="tab">Informasi Dasar</a></li>
                    <li><a href="#informasi_tambahan" data-toggle="tab">Informasi Tambahan</a></li>
                    <li><a href="#galeri" data-toggle="tab">Galeri Properti</a></li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active" id="informasi_dasar">
                        <legend><h5>Informasi Dasar</h5></legend>

                        <form method="post" id="input-form" class="form-horizontal" action="<?php echo $link; ?>">
                            <div class="control-group">
                                <label class="control-label" for="jenis_iklan">Jenis Iklan*:</label>
                                <div class="controls">
                                    <?php generate_input('span2','radio', $beli, 'sewa_beli',$sewa_beli,$isUpdate); ?>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="judul">Judul*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $nama?>" name="judul" id="judul">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="tipe">Jenis Properti*:</label>
                                <div class="controls">
                                    <select name="tipe" id="tipe" class="select-block span3">
                                    <?php
                                    generate_option($jenis,$tipe);
                                    ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="luas_tanah">Luas Tanah*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $luas_tanah?>" name="luas_tanah" id="luas_tanah">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="luas_bangunan">Luas Bangunan*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $luas_bangunan?>" name="luas_bangunan" id="luas_bangunan">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="jml_kmr_tidur">Kamar Tidur*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $jml_kmr_tidur?>" name="jml_kmr_tidur" id="jml_kmr_tidur">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="jml_kmr_mandi">Kamar Mandi*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $jml_kmr_mandi?>" name="jml_kmr_mandi" id="jml_kmr_mandi">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="jml_kmr_pembantu">Kamar Pembantu:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $jml_kmr_pembantu?>" name="jml_kmr_pembantu" id="jml_kmr_pembantu">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="harga">Harga*:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $harga?>" name="harga" id="harga">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="sertifikasi">Sertifikasi*:</label>
                                <div class="controls">
                                    <select name="sertifikasi" id="sertifikasi">
                                        <?php
                                        generate_option($sertifikasi,$sertifikat);
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="tahun_didirikan">Tahun Didirikan:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $tahun_didirikan?>" name="tahun_didirikan" id="tahun_didirikan">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="furnitur">Furnitur*:</label>
                                <div class="controls">
                                    <select name="furnitur" id="furnitur">
                                        <?php
                                        generate_option($furnitur,$furn);
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="tambahan_info_furnitur">Tambahan Info Furnitur:</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" value="<?php echo $tambahan_info_furnitur?>" name="tambahan_info_furnitur" id="tambahan_info_furnitur">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="provinsi">Provinsi*:</label>
                                <div class="controls">
                                    <select name="provinsi" id="provinsi" onchange="pilih_kota('dom_kota',this.value);">
                                        <option value="default">-- Pilih provinsi --</option>
                                        <?php
                                        generate_option($provinsi);
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="kota">Kota*:</label>
                                <div class="controls">
                                    <select name="kota" id="dom_kota">
                                        <option value="default">-- Pilih kota --</option>
                                    </select>
                                </div>
                            </div>
                            <div class="span3 offset2">
                                <input type="submit" name="submit"  class="btn btn-primary btn-small span3" value="Submit" />
                            </div>
                        </form>
                    </div>
                    <div class="tab-pane" id="informasi_tambahan">
                        <legend><h5>Informasi Tambahan</h5></legend>
                        <form method="post" id="input-form" class="form-horizontal"action="<?php echo $link; ?>">
                            <div class="control-group">
                                <label class="control-label" for="deskripsi">Deskripsi*:</label>
                                <div class="controls">
                                    <textarea name="deskripsi" id="deskripsi" value="" cols="50" rows="3" style="width:300px;"><?php echo $deskripsi ?></textarea>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="info_sekolah_rs">Informasi Sekolah &amp; Rumah Sakit:</label>
                                <div class="controls">
                                    <textarea name="info_sekolah_rs" id="info_sekolah_rs" value="" cols="50" rows="1" style="width:300px;"><?php echo $info_sekolah_rs ?></textarea>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="jalan">Alamat Lokasi*:</label>
                                <div class="controls">
                                    <textarea name="jalan" id="jalan" value="" cols="50" rows="3" style="width:300px;"><?php echo $jalan ?></textarea>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="area_spesifik">Area Spesifik:</label>
                                <div class="controls">
                                    <textarea name="area_spesifik" id="area_spesifik" value="" cols="50" rows="3" style="width:300px;"><?php echo $area_spesifik ?></textarea>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="fasilitas">Fasilitas:</label>
                                <div class="controls">               
                                <div class="span2">
                                    <?php
                                    $checked['kolam_renang'] = "";
                                    $checked['gym'] = "";
                                    $checked['sauna'] = "";
                                    $checked['tennis_court'] = "";
                                    $checked['jogging_track'] = "";
                                    $checked['library'] = "";
                                    $checked['mini_market'] = "";
                                    $checked['atm'] = "";
                                    $checked['function_room'] = "";
                                    $checked['children_playground'] = "";
                                    $checked['entertainment_center'] = "";
                                    $checked['shopping_center'] = "";

                                    $val['kolam_renang'] = 0;
                                    $val['gym'] = 0;
                                    $val['sauna'] = 0;
                                    $val['tennis_court'] = 0;
                                    $val['jogging_track'] = 0;
                                    $val['library'] = 0;
                                    $val['mini_market'] = 0;
                                    $val['atm'] = 0;
                                    $val['function_room'] = 0;
                                    $val['children_playground'] = 0;
                                    $val['entertainment_center'] = 0;
                                    $val['shopping_center'] = 0;

                                    if($isUpdate){

                                        if($output['kolam_renang']==1){
                                            $checked['kolam_renang'] = "checked";
                                            $val['kolam_renang'] = 1;
                                        }
                                        if($output['gym']==1){
                                            $checked['gym'] = "checked";
                                            $val['gym'] = 1;
                                        }
                                        if($output['sauna']==1){
                                            $checked['sauna'] = "checked";
                                            $val['sauna'] = 1;
                                        }
                                        if($output['tennis_court']==1){
                                            $checked['tennis_court'] = "checked";
                                            $val['tennis_court'] = 1;
                                        }
                                        if($output['jogging_track']==1){
                                            $checked['jogging_track'] = "checked";
                                            $val['jogging_track'] = 1;
                                        }
                                        if($output['mini_market']==1){
                                            $checked['mini_market'] = "checked";
                                            $val['mini_market'] = 1;
                                        }
                                        if($output['atm']==1){
                                            $checked['atm'] = "checked";
                                            $val['kolam_renang'] = 1;
                                        }
                                        if($output['library']==1){
                                            $checked['library'] = "checked";
                                        }
                                        if($output['shopping_center']==1){
                                            $checked['shopping_center'] = "checked";
                                        }
                                        if($output['children_playground']==1){
                                            $checked['children_playground'] = "checked";
                                        }
                                        if($output['function_room']==1){
                                            $checked['function_room'] = "checked";
                                        }
                                        if($output['entertainment_center']==1){
                                            $checked['entertainment_center'] = "checked";
                                        }
                                    }
                                    ?>
                                    <label class="checkbox <?php echo $checked['kolam_renang']; ?>" for="kolam_renang">
                                        <input type="checkbox" name="kolam_renang" for="mau_proyek" value="<?php echo $val['kolam_renang']; ?>" id="kolam_renang" data-toggle="checkbox">
                                        Kolam Renang
                                    </label>
                                    <label class="checkbox <?php echo $checked['gym']; ?>" for="gym">
                                        <input type="checkbox" name="gym" for="fasilitas" value="1" id="gym" data-toggle="checkbox">
                                        Gym
                                    </label>
                                    <label class="checkbox <?php echo $checked['sauna']; ?>" for="jacuzzi">
                                        <input type="checkbox" name="jacuzzi" for="fasilitas" value="1" id="jacuzzi" data-toggle="checkbox">
                                        Jacuzzi/Sauna
                                    </label>
                                    <label class="checkbox <?php echo $checked['tennis_court']; ?>" for="tennis_court">
                                        <input type="checkbox" name="tennis_court" for="fasilitas" value="1" id="tennis_court" data-toggle="checkbox">
                                        Tennis Court
                                    </label>
                                    <label class="checkbox <?php echo $checked['jogging_track']; ?>" for="jogging_track">
                                        <input type="checkbox" name="jogging_track" for="fasilitas" value="1" id="jogging_track" data-toggle="checkbox">
                                        Jogging Track
                                    </label>
                                    <label class="checkbox <?php echo $checked['function_room']; ?>" for="function_room">
                                        <input type="checkbox" name="function_room" for="fasilitas" value="1" id="function_room" data-toggle="checkbox">
                                        Function Room
                                    </label>
                                    </div>
                                </div>
                                <div class="span3">
                                    <label class="checkbox <?php echo $checked['children_playground']; ?>" for="children_playground">
                                        <input type="checkbox" name="children_playground" for="mau_proyek" value="1" id="children_playground" data-toggle="checkbox">
                                        Children Playground
                                    </label>
                                    <label class="checkbox <?php echo $checked['atm']; ?>" for="atm">
                                        <input type="checkbox" name="atm" for="fasilitas" value="1" id="atm" data-toggle="checkbox">
                                        ATM
                                    </label>
                                    <label class="checkbox <?php echo $checked['mini_market']; ?>" for="mini_market">
                                        <input type="checkbox" name="mini_market" for="fasilitas" value="1" id="mini_market" data-toggle="checkbox">
                                        Mini Market
                                    </label>
                                    <label class="checkbox <?php echo $checked['library']; ?>" for="library">
                                        <input type="checkbox" name="library" for="fasilitas" value="1" id="library" data-toggle="checkbox">
                                        Library
                                    </label>
                                    <label class="checkbox <?php echo $checked['shopping_center']; ?>" for="shopping_center">
                                        <input type="checkbox" name="shopping_center" for="fasilitas" value="1" id="shopping_center" data-toggle="checkbox">
                                        Shopping Center
                                    </label>
                                    <label class="checkbox <?php echo $checked['entertainment_center']; ?>" for="entertaintment_center">
                                        <input type="checkbox" name="entertaintment_center" for="fasilitas" value="1" id="entertaintment_center" data-toggle="checkbox">
                                        Entertainment Center
                                    </label>
                                    
                                </div>
                            </div>
                            <div class="span3 offset2">
                                <input type="submit" name="submit"  class="btn btn-primary btn-small span3" value="Submit" />
                            </div>
                        </form>
                    </div>
                    <div class="tab-pane" id="galeri">
                        <form id="fileupload" action="<?php echo $link; ?>" method="POST" enctype="multipart/form-data">
                            <!-- Redirect browsers with JavaScript disabled to the origin page -->
                            <noscript><input type="hidden" name="redirect" value="http://blueimp.github.io/jQuery-File-Upload/"></noscript>
                            <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
                            <div class="row fileupload-buttonbar">
                                <div class="col-lg-7">
                                    <!-- The fileinput-button span is used to style the file input field as button -->
                                    <span class="btn btn-success fileinput-button">
                                        <i class="glyphicon glyphicon-plus"></i>
                                        <span>.. Tambah Files..</span>
                                        <input type="file" name="img[]" multiple>
                                    </span>
                                    <button type="submit" class="btn btn-primary start">
                                        <i class="glyphicon glyphicon-upload"></i>
                                        <span>Start upload</span>
                                    </button>
                                    <button type="reset" class="btn btn-warning cancel">
                                        <i class="glyphicon glyphicon-ban-circle"></i>
                                        <span>Cancel upload</span>
                                    </button>
                                    <button type="button" class="btn btn-danger delete">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <span>Delete</span>
                                    </button>
                                    <input type="checkbox" class="toggle">
                                    <!-- The loading indicator is shown during file processing -->
                                    <span class="fileupload-loading"></span>
                                </div>
                                <!-- The global progress information -->
                                <div class="col-lg-5 fileupload-progress fade">
                                    <!-- The global progress bar -->
                                    <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                                        <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                    </div>
                                    <!-- The extended global progress information -->
                                    <div class="progress-extended">&nbsp;</div>
                                </div>
                            </div>
                            <!-- The table listing the files available for upload/download -->
                            <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $('.fileupload').fileupload();
</script>